﻿package mortal.game.view.copy.singleTowerCopy2.panel
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.copy.singleTowerCopy2.data.*;
    import mortal.mvc.core.*;

    public class SingleTowerPassPanel extends Window
    {
        protected var _bg:GImageBitmap;
        protected var _title:GImageBitmap;
        protected var _passTitle:GImageBitmap;
        protected var _rwBg:ScaleBitmap;
        protected var _rwList:CellsGridSprite;
        protected var _pageSelector:PageSelecter;
        protected var _leaveBtn:GLoadingButton;
        protected var _title2:GImageBitmap;
        protected var _totalDes:GBitmap;
        protected var _allPassTip:GImageBitmap;
        protected var _midTip:GImageBitmap;
        protected var _totalNum:BitmapNumberText;
        protected var _curAndTotalNum:BitmapNumberText;
        protected var _passLv:BitmapNumberText;
        protected var _titldPass:BitmapNumberText;
        private var _pageTool:PageTool;
        private var _GiftLen:int = 4;
        private var _resLoad:Boolean = false;
        private var _info:STowerCopy4EndMsg;
        private static var _instance:SingleTowerPassPanel;
        public static var canShow:Boolean = false;

        public function SingleTowerPassPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.sigleTowerCopy, this.onShow);
            return;
        }// end function

        private function onShow() : void
        {
            this._resLoad = true;
            this._bg = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTipBg, 0, -56, this);
            this._title = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTitle, 178, 33, this);
            this._passTitle = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTipTitlePass, 108, -41, this);
            this._rwBg = UIFactory.bg(187, 83, 384, 118, this, ImagesConst.PanelBg);
            this._rwList = UIFactory.getUICompoment(CellsGridSprite);
            this._rwList.colNum = 4;
            this._rwList.vCellWid = 75;
            this._rwList.hCellWid = 100;
            this._rwList.genCellFun = this.genCells;
            this._rwList.genCells(4);
            this._rwList.x = 235;
            this._rwList.y = 93;
            this.addChild(this._rwList);
            this._pageSelector = UIFactory.pageSelecter(345, 170, this, PageSelecter.SingleMode);
            this._pageSelector.setbgStlye(ImagesConst.ComboBg, GlobalStyle.textFormatBai.center());
            this._pageSelector.maxPage = 1;
            this._pageSelector.pageTextBoxSize = 36;
            this._pageSelector.configEventListener(Event.CHANGE, this.onPageChange);
            this._leaveBtn = UIFactory.gLoadingButton(ImagesConst.leaveCopy2Btn_upSkin, 334, 253, 114, 34, this);
            this._leaveBtn.label = "";
            this._title2 = UIFactory.gImageBitmap(ImagesConst.SingleTowerTip3, 113, -44, this);
            this._totalDes = UIFactory.gBitmap(ImagesConst.SigleTowerCopyPassTotalLvDes, 267, 203, this);
            this._allPassTip = UIFactory.gImageBitmap(ImagesConst.SingleTowerPassTip2, 176, 30, this);
            this._midTip = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTip, 201, 227, this);
            this._totalNum = UIFactory.bitmapNumberText(345, 199, "SingleTowerCopyNum.png", 22, 31, -6, this, 12, 1);
            this._totalNum.text = "20";
            this._curAndTotalNum = UIFactory.bitmapNumberText(382, 200, "SingleTowerCopyNum.png", 22, 31, -6, this, 12, 0);
            this._curAndTotalNum.text = "(7-20)";
            this._passLv = UIFactory.bitmapNumberText(335, 37, "SingleTowerCopyNum.png", 22, 31, -6, this, 12, 1);
            this._passLv.text = "20";
            this._titldPass = UIFactory.bitmapNumberText(503, -23, "OpenNewSerSevNum.png", 38, 43, -10, this, 9, 1);
            this._titldPass.text = "20";
            this._pageTool = new PageTool([], 4);
            this.width = 770;
            var _loc_1:Boolean = false;
            this._allPassTip.visible = false;
            this._passTitle.visible = _loc_1;
            this._leaveBtn.configEventListener(MouseEvent.CLICK, this.onLeaveFB);
            this.updateInfo(this._info);
            this.x = (Global.stage.stageWidth - this.width) / 2;
            this.y = (Global.stage.stageHeight - this.height) / 2;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._resLoad = false;
            LoaderHelp.removeResEvent(ResFileConst.sigleTowerCopy, this.onShow);
            this._pageTool = null;
            this._bg = null;
            this._title = null;
            this._passTitle = null;
            this._rwBg = null;
            this._rwList = null;
            this._pageSelector = null;
            this._leaveBtn = null;
            this._title2 = null;
            this._totalDes = null;
            this._allPassTip = null;
            this._midTip = null;
            this._totalNum = null;
            this._curAndTotalNum = null;
            this._passLv = null;
            this._titldPass = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function genCells() : BaseItem
        {
            var _loc_1:* = UIFactory.getUICompoment(BaseItem);
            _loc_1.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            return _loc_1;
        }// end function

        private function onPageChange(event:Event) : void
        {
            var _loc_4:BaseItem = null;
            var _loc_5:ItemData = null;
            var _loc_2:* = this._pageTool.getByPageNo(this._pageSelector.currentPage);
            this._rwList.genCells(this._GiftLen);
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length && _loc_3 < this._rwList.cellArr.length)
            {
                
                _loc_4 = this._rwList.cellArr[_loc_3];
                _loc_5 = _loc_2[_loc_3];
                _loc_4.itemData = _loc_5;
                _loc_3++;
            }
            return;
        }// end function

        private function updateRw(param1:Dictionary) : void
        {
            var _loc_3:String = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:ItemData = null;
            var _loc_2:Array = [];
            for (_loc_3 in param1)
            {
                
                _loc_4 = int(_loc_3);
                _loc_5 = int(param1[_loc_3]);
                _loc_6 = new ItemData(_loc_4);
                _loc_6.itemAmount = _loc_5;
                _loc_2.push(_loc_6);
            }
            if (_loc_2)
            {
                this._pageTool.array = _loc_2;
                this._pageSelector.maxPage = Math.ceil(_loc_2.length / this._GiftLen);
                this.onPageChange(null);
            }
            return;
        }// end function

        public function updateInfo(param1:STowerCopy4EndMsg) : void
        {
            this._info = param1;
            if (this._info == null || this._resLoad == false)
            {
                return;
            }
            var _loc_2:* = this.getTotalNum(param1.copyCode);
            var _loc_3:* = "" + param1.endLevel;
            this._passLv.text = "" + param1.endLevel;
            this._titldPass.text = _loc_3;
            this._totalNum.text = "" + _loc_2;
            this._curAndTotalNum.text = "(" + param1.endLevel + "-" + _loc_2 + ")";
            if (param1.endLevel == _loc_2)
            {
                var _loc_3:Boolean = true;
                this._allPassTip.visible = true;
                this._passTitle.visible = _loc_3;
                var _loc_3:Boolean = false;
                this._title.visible = false;
                var _loc_3:* = _loc_3;
                this._passLv.visible = _loc_3;
                var _loc_3:* = _loc_3;
                this._titldPass.visible = _loc_3;
                this._title2.visible = _loc_3;
            }
            else
            {
                var _loc_3:Boolean = false;
                this._allPassTip.visible = false;
                this._passTitle.visible = _loc_3;
                var _loc_3:Boolean = true;
                this._title.visible = true;
                var _loc_3:* = _loc_3;
                this._passLv.visible = _loc_3;
                var _loc_3:* = _loc_3;
                this._titldPass.visible = _loc_3;
                this._title2.visible = _loc_3;
            }
            this.updateRw(param1.rewards);
            return;
        }// end function

        private function getTotalNum(param1:int) : int
        {
            return SingleTowerCopyUtil.getTotalLvByCode(param1);
        }// end function

        private function onNextBtn(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            Dispatcher.dispatchEvent(new DataEvent(EventName.SingleTower2EnterNextCk, _loc_2));
            this.hide();
            return;
        }// end function

        private function onLeaveFB(event:MouseEvent) : void
        {
            this.hide();
            if (Cache.instance.copy.copyInfo == null)
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            return;
        }// end function

        public static function get instance() : SingleTowerPassPanel
        {
            if (_instance == null)
            {
                _instance = new SingleTowerPassPanel;
            }
            return _instance;
        }// end function

        public static function get isView() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
